import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import '../../pages/station/station_equip_edit.dart';
import '../../pages/station/station_equip_info.dart';
import '../../helper/routeHelper.dart';
import '../../widgets/IconWidget.dart';
import '../../widgets/inputWidget.dart';

import '../../helper/cacheHelper.dart';

import '../../model/station.dart';
import '../../widgets/someCards.dart';

import '../../model/stationequip.dart';

class StationEquipListPage extends StatefulWidget {
  @override
  StationEquipListPage(this.s1);
  final Station s1;

  @override
  StationEquipListPageState createState() => new StationEquipListPageState();
}

class StationEquipListPageState extends State<StationEquipListPage> {
  late List<StationEquip> EquipList;

  @override
  initState() {
    super.initState();

    getAllEquipList();
  }

  void getAllEquipList() async {
    var _list = await StationEquip.GetList(
        "StationGuid=@ID", {"ID": widget.s1.Guid}, 0, 500);

    setState(() {
      EquipList = _list;
    });
  }

  List<Widget> getEquipList(BuildContext context) {
    var _list1 = <Widget>[];

    List<Widget> list1 = <Widget>[];
    list1.add(InputWidget.inCard(
      ListTile(
        leading: IconWidget.RiverImage(),
        title: Text("主要设备"),
      ),
    ));

    for (StationEquip a in EquipList) {
      _list1.add(InputWidget.getInfo(a.Name, a.FactureTime,
          onTap: () => RouteHelper.ShowPage(
              context, StationEquipInfoPage(a, widget.s1, getAllEquipList))));
      _list1.add(Divider(
        height: 1.0,
      ));
      //_list1.add( SomeCard.StationEquipCard(context, a ));
    }

    list1.add(InputWidget.inCard2(_list1));
    return list1;
  }

  Widget getBody(BuildContext context) {
    if (EquipList == null)
      return Center(
          child: SpinKitCircle(
        color: Colors.blue,
      ));
    // TODO: implement build
    return new Scaffold(
        floatingActionButton: Container(
            //margin: EdgeInsets.all(16.0),
            child: FloatingActionButton(
                child: Icon(Icons.add),
                onPressed: () {
                  StationEquip xxx = new StationEquip(
                      0, widget.s1.Guid, "", "", "", "", "", "");
                  RouteHelper.ShowPage(context,
                      StationEquipAddPage(xxx, widget.s1, getAllEquipList));
                })),
        body: SingleChildScrollView(
            // margin: EdgeInsets.only(top: 8.0),
            child: Column(children: getEquipList(context))));
  }

  @override
  Widget build(BuildContext context) {
    //getStation();
    return getBody(context);
  }
}
